'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 6_study_llm_retry.py
* @Time: 2025/10/24
* @All Rights Reserve By Brtc
'''
from langchain_core.runnables import RunnableLambda

counter = -1
def func(x):
    global counter
    counter += 1
    print("当前值:", counter)
    if counter == 3:
        return 3
    else:
        return x/0

chain = RunnableLambda(func).with_retry(stop_after_attempt=5)
resp = chain.invoke({"x":2})
print(resp)